//
//  GuideViewController.m
//  QuickRentDemo
//
//  Created by xiebingqing on 2016/11/8.
//  Copyright © 2016年 xiebingqing. All rights reserved.
//

#import "GuideViewController.h"


#import "ViewController.h"
#import "AppDelegate.h"
@interface GuideViewController ()

{
    NSArray *_imageArr;
    UIScrollView *_guideScrollView;
    UIButton *_welcomeBtn;
}

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _imageArr = @[@"guid_two",@"guid_three",@"guid_fore"];
    _guideScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, B_HEIGHT)];
    _guideScrollView.contentSize = CGSizeMake(B_WIDTH*3, B_HEIGHT);
    _guideScrollView.pagingEnabled = YES;
    _guideScrollView.showsHorizontalScrollIndicator = NO;
    _guideScrollView.bounces = NO;
    _guideScrollView.backgroundColor = [UIColor greenColor];
    
    for (int i = 0; i < _imageArr.count; i++)
    {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(B_WIDTH*i, 0,B_WIDTH, B_HEIGHT)];
        NSString *imageName = [_imageArr objectAtIndex:i];
        imageView.image = [UIImage imageNamed:imageName];
        [_guideScrollView addSubview:imageView];
    }
    _welcomeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _welcomeBtn.frame = CGRectMake(10 + B_WIDTH * 2, B_HEIGHT*0.856, B_WIDTH-20,B_HEIGHT*0.0679 );

    [_welcomeBtn addTarget:self action:@selector(welcomeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_guideScrollView addSubview:_welcomeBtn];
    
    self.view.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:_guideScrollView];
    
    
}

-(void)welcomeBtnClick:(UIButton *)btn
{
    
    ViewController *customVC = [[ViewController alloc] init];
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    app.window.rootViewController = customVC;
    // 获取到存储用户默认信息的对象
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    // 往硬盘上存储一个BOOl 类型的值 键是guide
    // 键的作用是方便我们下一次能够从硬盘上取出所保存的值
    [ud setBool:YES forKey:@"guide"];
    // 同步 （把要存储的值立刻写入硬盘）
    [ud synchronize];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
